import React, { Component } from 'react'
import '../css/style.css'
import event from '../../events'
class Header extends Component {
    render() {
        return (
            <div className='header_container'>
                <div>
                    <h2>ToDoList</h2>
                    <input placeholder='添加ToDo' ref='input' onKeyDown={(e) => {
                        if (e.keyCode === 13) {
                            var value = this.refs.input.value;
                            if (value.length === 0) {
                                alert('请输入内容');
                                return
                            }
                            var id = JSON.parse(localStorage.getItem('done')) || ''
                            var message = {
                                value: value,
                                type: false,
                                id: id.length
                            }
                            event.emit('add', message)
                            this.refs.input.value = ''
                        }
                    }} />
                </div>
            </div>
        )
    }
}
export default Header